package 如何初始化数组;

import java.util.Scanner;

public class 数组反转23 {
	public static void main(String[] args) {
        Scanner abc = new Scanner(System.in);
        System.out.println("请输入数组的数字个数：");
        int num = abc.nextInt();
        int[] a;
        a = new int[num];
        int b = 0;
        System.out.println("数组的每个数字是：");
        for (int j = 0; j < a.length; j++) {
            a[j] = (int) (Math.random() * 100);
            System.out.println(a[j]);
        }
        if (a.length % 2 == 1) {
            for (int i = 1; i <= (int) a.length / 2; i++) {
 
                // 以中心数字为基准,后一个值赋给b
                b = a[((int) (a.length / 2)) + i];
                a[((int) (a.length / 2)) + i] = a[((int) (a.length / 2)) - i];
                a[((int) (a.length / 2)) - i] = b;
 
            }
        } else {
            for (int i = 0; i < a.length / 2; i++) {
                b = a[a.length / 2 + i];
                a[a.length / 2 + i] = a[a.length / 2 - 1 - i];
                a[a.length / 2 - 1 - i] = b;
 
            }
 
        }
 
        System.out.println("新的数组是：");
        for (int j = 0; j < a.length; j++) {
 
            System.out.println(a[j]);
        }
    }
}